package com.epfly.promo.activity.impl.discount.predicate;

import com.epfly.iface.promo.activity.enums.EffectiveOrderMethodsEnum;
import com.epfly.promo.activity.entity.ActivityEntity;
import com.epfly.promo.activity.impl.ActivityUtil;
import com.epfly.promo.activity.impl.discount.ActivityWrapper;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Service;

/**
 * 下单方式校验
 */
@Order(value = PredicateOrder.ORDER_METHOD_ORDER)
@Service
public class OrderMethodPredicate implements ActivityDiscountPredicate {

    @Override
    public boolean test(ActivityWrapper activityWrapper) {

        ActivityEntity activityEntity = activityWrapper.getActivityEntity();
        String effectiveTakeMethods = activityEntity.getEffectiveTakeMethods();

        // 优惠活动下单方式设置为"不限"
        if (effectiveTakeMethods.equals(ActivityUtil.join(EffectiveOrderMethodsEnum.NO_LIMIT.getKey()))) {
            return true;
        }

        // 优惠活动设置的"下单方式"包含当前订单的"下单方式"
        return effectiveTakeMethods.contains(ActivityUtil.join(activityWrapper.getOrderMethod()));
    }
}
